<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="formRef"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="企业名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="公司法人" prop="legalPerson">
        <el-input v-model="ruleForm.legalPerson"></el-input>
      </el-form-item>
      <el-form-item label="注册资本" prop="capital">
        <el-input v-model="ruleForm.capital"></el-input>
      </el-form-item>
      <el-form-item label="所属行业" prop="profession">
        <el-input v-model="ruleForm.profession"></el-input>
      </el-form-item>
      <el-row :gutter="20">
        <el-col :span="12" :offset="0">
          <el-form-item label="企业LOGO" prop="logo">
            <img-upload v-model="ruleForm.logo" />
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="营业执照" prop="license">
            <img-upload v-model="ruleForm.license" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="公司位置" prop="address">
        <el-row style="width: 100%">
          <el-col :span="20" :offset="0">
            <el-input v-model="ruleForm.address" readonly></el-input>
          </el-col>
          <el-col :span="4" :offset="0">
            <el-button type="primary" size="default" @click="drawer = true"
              >点击选址</el-button
            >
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="是否上架" prop="stat">
        <el-switch v-model="ruleForm.stat"></el-switch>
      </el-form-item>
      <el-form-item label="公司简介" prop="intro">
        <div class="editor">
          <QuillEditor v-model:content="ruleForm.intro" contentType="html" />
        </div>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-drawer v-model="drawer" title="地图选址" direction="btt" size="60%">
      <GodMap v-model="ruleForm.address" @close-drawer="drawer = false" />
    </el-drawer>
  </div>
</template>
<script>
import { companyPost } from "@/api/job.js";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import GodMap from "./components/god-map";
export default {
  components: {
    QuillEditor,
    GodMap,
  },
  data() {
    return {
      drawer: true,
      ruleForm: {
        name: "万峰互联",
        legalPerson: "袍哥",
        capital: "10000万",
        profession: "沐浴行业",
        intro: "",
        license: "",
        logo: "",
        address: "",
      },
      rules: {
        name: [{ required: true, message: "请输入信息", trigger: "blur" }],
        legalPerson: [
          { required: true, message: "请输入信息", trigger: "blur" },
        ],
        capital: [{ required: true, message: "请输入信息", trigger: "blur" }],
        profession: [
          { required: true, message: "请输入信息", trigger: "blur" },
        ],
        intro: [{ required: true, message: "请输入信息", trigger: "blur" }],
        logo: [{ required: true, message: "请上传logo", trigger: "blur" }],
        license: [
          { required: true, message: "请上传营业执照", trigger: "blur" },
        ],
      },
      cateList: [], //下拉列表数据
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          console.log(this.ruleForm);
          companyPost(this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style lang="scss">
.editor {
  /* border: 1px solid #d8d8d8; */
  height: 300px;
  width: 100%;
  /* overflow: hidden; */
  margin-bottom: 50px;
}
</style>
